package com.hsylient.javase.chapter11.demo04;

/**
 * 线程的停止
 * <p>
 * 推荐方法使用一个标记位
 */
public class ThreadStop implements Runnable {

    private Boolean flag = Boolean.TRUE;

    @Override
    public void run() {
        for (int i = 0; i < 100000000; i++) {
            if (flag) {
                System.out.println("子线程。。。。" + i);
            }
        }
    }

    public void stopThread() {
        this.flag = Boolean.FALSE;
    }
}
